<template>
	<view class="login">
		<view class="login-form">
			<u-field
						v-model="mobile"
						label="手机号"
						placeholder="请填写手机号"
						required
						:error-message="errorMobileMessage"
					>
					</u-field>
					<u-field
						v-model="password"
						label="密码"
						placeholder="请填写密码"
						required
						password
						:error-message="errorPasswordMessage"
					>
					</u-field>
						<u-top-tips ref="uTips" ></u-top-tips>
					<u-button type="success" style="margin-top:50rpx" @click="login">登录</u-button>
		</view>
	</view>
</template>

<script>
	export default{
		data() {
					return {
						mobile:'',
						password:'',
						errorMobileMessage:'',
						errorPasswordMessage:'',
					}
				},
		methods:{
		 login(){
			 var that=this
				try{
					this.$request({
							url:"/login/cellphone",
							method:'post',
							data:{
								phone:that.mobile,
								password:that.password
							}
						}).then(res=>{
							console.log(res)
							let user=res.data
							try{
								 uni.setStorageSync('user', user);
								 that.$refs.uTips.show({
								 				title: '登录成功',
												type:'success'
								 			});
								uni.switchTab({
									url:'/pages/user/user',
									success:function(){
										that.$refs.uTips.show({
														title: '跳转成功',
														type:'success'
													});
									},
									fail:function(){
										that.$refs.uTips.show({
														title: '跳转失败',
														type:'error'
													});
									}
								})
							}catch(err){
								that.$refs.uTips.show({
												title: '登录失败',
												type:'error'
											});
							}
							
							
						})
				}catch(err){
					console.log(err)
					that.$refs.uTips.show({
									title: '登录失败',
									type:'error'
								});
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.login-form{
		width: 100%;
		margin-top:calc(50vh - 260rpx) ;
	}
</style>
